package 华为OD机试B卷复用题.进阶题;

import utils.MyUtil;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class HJ5_火星文计算 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试B卷复用题/进阶题/input/5.txt"));
        MyUtil.START();
        Solution(in);
        MyUtil.END();
    }

    // 用递归比较好理解一点
    static void Solution(Scanner in) {
        String s = in.nextLine();
        System.out.println(getNum(s));
    }

    static long getNum(String x) {
        int jingIndex = x.lastIndexOf("#");
        if (jingIndex != -1) {
            String left = x.substring(0, jingIndex);
            String right = x.substring(jingIndex + 1);
            System.out.println("# " + left + " " + right);
            return 2 * getNum(left) + 3 * getNum(right) + 4;
        }
        int dollarIndex = x.lastIndexOf("$");
        if (dollarIndex != -1) {
            String left = x.substring(0, dollarIndex);
            String right = x.substring(dollarIndex + 1);
            System.out.println("$ " + left + " " + right);
            return 3 * getNum(left) + getNum(right) + 2;
        }
        return Long.parseLong(x);
    }
}
